package com.liangwj.springbootdesignpatterns.structureTypePatterns.composite.demo_1;

import java.math.BigDecimal;

public class CompositeDemo1Test {

    public static void main(String[] args) {
        //CEO
        Employee CEO = new Employee("John", "CEO", new BigDecimal(30000));

        //销售主管
        Employee headSales = new Employee("Robert", "Head Sales", new BigDecimal(20000));

        //市场营销
        Employee headMarketing = new Employee("Michel", "Head Marketing", new BigDecimal(20000));

        //营业员_1
        Employee clerk_1 = new Employee("Laura", "Marketing", new BigDecimal(10000));

        //营业员_2
        Employee clerk_2 = new Employee("Bob", "Marketing", new BigDecimal(10000));

        //销售主管_1
        Employee salesExecutive_1 = new Employee("Richard", "Sales", new BigDecimal(10000));

        //销售主管_2
        Employee salesExecutive_2 = new Employee("Rob", "Sales", new BigDecimal(10000));

        CEO.add(headSales);
        CEO.add(headMarketing);

        headSales.add(salesExecutive_1);
        headSales.add(salesExecutive_2);

        headMarketing.add(clerk_1);
        headMarketing.add(clerk_2);

        //打印该组织所有员工
        System.out.println(CEO);

        //迭代
        printSub(CEO);
        /*for (Employee headEmployee : CEO.getSubordinates()) {
            System.out.println(headEmployee);
            for (Employee employee : headEmployee.getSubordinates()) {
                System.out.println(employee);
            }
        }*/

    }

    private static void printSub(Employee root) {
        for (Employee employee : root.getSubordinates()) {
            System.out.println(employee);
            if (!employee.getSubordinates().isEmpty()) {
                printSub(employee);
            }
        }
    }
}
